<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\BrandJoinPlan;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BrandJoinPlanController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BrandJoinPlan(['user:id,avatar,nickname','brand:id,name','profession:id,name']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.avatar','用户头像')->image('',80,80);
            $grid->column('user.nickname','用户昵称');
            $grid->column('brand.name','品牌名称');
            $grid->column('profession.name','品牌行业');
            $grid->column('investment_budget');
            $grid->column('plan_time');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableActions();
            $grid->disableCreateButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->like('user.nickname','用户昵称')
                       ->width(3);
                $filter->like('brand.name','品牌名称')
                        ->width(3);
                $filter->like('profession.name','品牌行业')
                       ->width(3);

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BrandJoinPlan(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('brand_id');
            $show->field('profession_id');
            $show->field('investment_budget');
            $show->field('plan_time');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BrandJoinPlan(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('brand_id');
            $form->text('profession_id');
            $form->text('investment_budget');
            $form->text('plan_time');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
